<?php
namespace Admin\Controller;

class LinkController extends CommonController {
    private $links;
    public function __construct()
    {
        parent::__construct();
        $this->links=M("link");
    }

    public function index()
    {
        $links=$this->links->order('sort_order')->select();
        $this->assign('links',$links);
        $this->display();
    }

    function store(){
        $this->links->create();
        $this->links->add();
        $this->success('新增成功');
    }

    function destroy(){
        $id = I('get.id');
        $this->links->delete($id);
        $this->success('删除成功');
    }

    function update(){

        $this->links->create();
        $this->links->save();
        $this->success('修改成功');

    }

    function destroy_checked(){
        $delete_id=I('post.delete_id');
        foreach ($delete_id as $id){
            $this->links->delete($id);
        }
        $this->success('删除成功');
    }

    function sort_order(){
        $sort_order = I('post.sort_order');
        $id = I('post.id');
        foreach ($id as $key => $value){
            $this->links->where("id=$value")->setField('sort_order',$sort_order[$key]);

        }
        $this->redirect('index');
    }
}